	package com.redpack.redpost.struts.action;

	import java.util.ArrayList;
import java.util.List;

	import javax.servlet.http.HttpServletRequest;
	import javax.servlet.http.HttpServletResponse;
	import javax.servlet.http.HttpSession;

	import org.apache.struts.action.Action;
	import org.apache.struts.action.ActionForm;
	import org.apache.struts.action.ActionForward;
	import org.apache.struts.action.ActionMapping;

	import com.redpack.redpost.struts.form.buscarForm;
	import com.redpack.redpost.util.dao.UserDAO;
	import com.redpack.redpost.util.dao.adminDAO;
	import com.redpack.redpost.util.to.HTMLEntities;
	import com.redpack.redpost.util.to.UserLogin;
	import com.redpack.redpost.util.to.generalUtil;
	import com.redpack.redpost.util.to.validaciones;
import com.redpack.redpost.util.dao.*;


	public class buscar extends Action {
		
		public ActionForward execute(
				ActionMapping mapping, 
				ActionForm form, 
				HttpServletRequest request, 
				HttpServletResponse response) throws Exception {
			
			HttpSession session = request.getSession( ) ;
			
			buscarForm f = ( buscarForm ) form ;
			String words = f.getWords();
			
			
			String success = "success",
					idioma = "";
			
			
			if ( session.getAttribute("idioma") != null ){
				idioma = session.getAttribute("idioma").toString();
			}
			
			success = success +""+ idioma ;
			
			if(request.getParameter("hd_buscador") != null && request.getParameter("hd_buscador") != ""){

				words = generalUtil.removeHTML(request.getParameter("hd_buscador").toString());
				words = generalUtil.removeCaracters(words);
				List Busqueda = new ArrayList(); 
				
				Busqueda = BusquedaDao.getBusqueda(words,idioma);
				int cont = 0;
				
				request.setAttribute("cont",""+ cont);
				request.setAttribute("words",""+ words);
				
				if(!Busqueda.isEmpty()){
				    cont = Busqueda.size();
					
					request.setAttribute("cont",""+ cont);
					request.setAttribute("Busqueda", Busqueda);
					request.setAttribute("words",""+ words);
				}

		}
			
			UserLogin login = null ;
			String nombre = "",
					apellido = "" ;
			
			int id_seccion = 1,
					numSlides = 0;
			
			if( generalUtil.isLoggedIn( request ) ){
				
				login = (UserLogin) session.getAttribute("UserLogin") ;
				nombre = login.getNombre( ) ;
				apellido = login.getApellido( ) ;
				
				request.setAttribute("Nombre", nombre) ;
				request.setAttribute("Apellido", apellido) ;
				
			}
			
			try{
				
				ArrayList slides =  UserDAO.slidesHome( 1, idioma ) ;
				
				if( !slides.isEmpty( ) )
					numSlides = slides.size( ) ;
							
				request.setAttribute("Slides", slides) ;
				
			}catch( Exception e ){
				e.printStackTrace( ) ;
			}
			
			//request.setAttribute("words", words) ;
			request.setAttribute("User", login) ;
					
			return mapping.findForward(success);
			
			}
		
		
		
		

	}